#ifndef __SDK_IFS_UDK_CFG_H__
#define __SDK_IFS_UDK_CFG_H__

#include "sdk_core/rc24xx.h"
#include "sdk_core/rom_def.h"
#include "sys_radar_def.h"

/*rom or xip starup*/
#define APPLICATION_MODE (0)  // 0-ROM mode 1-XIP mode
/*ota size set*/
// 工具识别该宏，必须为16进制格式，32KB,必须为4K整数倍
#define OTA_SIZE_MAX (0x8000)

/* --------------------------------------------------------------------------------
udk_cfg 系统区 不可修改*/

#define UDK_ASSERT(x) if( !(x) ){udsf_uart_send_string("\nassert failed:"); udsf_uart_send_string(#x);while(1);}

#define APPLICATION_MODE_ROM_START (0)
#define APPLICATION_MODE_XIP_START (1)

#define UDK_VERSION_SE   (1)
#define UDK_VERSION_LITE (2)
#define UDK_VERSION_STD  (3)

/*
可修改值,但不要更改格式(防止gene_bin.exe解析本文件异常)*/
// 1:udk-se 2:udk-lite 3:udk-std
#define UDK_MODE_SETS (3)

#define UDK_VERSION 0x2300 // 2.30.0
#define UDK_VERSION_APPEND "2311011514"

#define UDK_SE_UDF_START_ADDR       (1024*32)  // 内部32K
#define UDK_SE_UDP_START_ADDR       (1024*44)  // 内部44K
#define UDK_SE_RSV_START_ADDR       (1024*47)  // 内部47K
#define UDK_LITE_UDF_START_ADDR     (1024*18)  // 外部[SYSBIN_SIZE_MAX+]18K
#define UDK_LITE_UDP_START_ADDR     (1024*14)  // 外部[SYSBIN_SIZE_MAX+]14K
#define UDK_LITE_RSV_START_ADDR     (1024*17)  // 外部[SYSBIN_SIZE_MAX+]17K
#define UDK_STD_UDF_START_ADDR      (1024*36)  // 外部[SYSBIN_SIZE_MAX+]36K
#define UDK_STD_UDP_START_ADDR      (1024*32)  // 外部[SYSBIN_SIZE_MAX+]32K
#define UDK_STD_RSV_START_ADDR      (1024*35)  // 外部[SYSBIN_SIZE_MAX+]32K
#define IIC_Para_ADDR               (1024*120)
#define PIN_Para_ADDR               (1024*100)

#define USRBOOT_INFO_OFFSET         (1024*0 )  // usrboot INFO区偏移
#define USRBOOT_INFO_SIZE_PRE       (1024*4)   // usrboot INFO区 子区大小（共2个子区）
#define USRBOOT_UDP_DEFAULT_OFFSET  (UDK_STD_UDP_START_ADDR)  // usrboot 默认应用UDP地址

#if UDK_MODE_SETS == 1
#define UDF_START_ADDR (UDK_SE_UDF_START_ADDR)
#define UDP_START_ADDR (UDK_SE_UDP_START_ADDR)
#define APP_RSV_ADDR   (UDK_SE_RSV_START_ADDR+8)
#elif UDK_MODE_SETS == 2
#define UDF_START_ADDR (UDK_LITE_UDF_START_ADDR)
#define UDP_START_ADDR (UDK_LITE_UDP_START_ADDR)
#define APP_RSV_ADDR   (UDK_LITE_RSV_START_ADDR+8)
#elif UDK_MODE_SETS == 3
#define UDF_START_ADDR (UDK_STD_UDF_START_ADDR)
#define UDP_START_ADDR (UDK_STD_UDP_START_ADDR)
#define APP_RSV_ADDR   (UDK_STD_RSV_START_ADDR+8)
#endif

/* --------------------------------------------------------------------------------
SDK adapter 不可更改*/

// all sdk 可用
#define p_sdk_version    ((uint8_t*) (0x20000048))
#define p_work_mode      ((uint8_t*) (0x20000049))

// sdk >= 1.0可用
#define p_gb_sysboot     ((GLOBAL_PARAM*)(0x20000000))

#if ( SDK_VERSION <= SDK_VERSION_GENE(0,2) )
#error sdk version must more than 0.2
#elif ( SDK_VERSION >= SDK_VERSION_GENE(1,0) )
#if (APPLICATION_MODE == APPLICATION_MODE_ROM_START)
#error SDK_1.x do not support rom start
#endif
#endif

#define bbe_regb_str   ((BBE_REGB_T *)      (0x30080000))
#define ana_Venus_st   ((ANA_VEUNS_ST *)    (0x4002C000))
#define paramANA_Venus ((PARAM_ANA_VENUS *) (UDP_ADDR+0x000))
#define paramDataPrep  ((PARAM_DATAPREP *)  (UDP_ADDR+0x080))
#define paramALG       ((PARAM_ALGORITHM *) (UDP_ADDR+0x100))
#define paramFunc      ((PARAM_FUNC *)      (UDP_ADDR+0x640))
#define paramRSV       ((PARAM_RSV*)        (UDP_ADDR+0x728))

#if (APPLICATION_MODE == APPLICATION_MODE_ROM_START)

#define UART_RECV_STRUCT_BASE (0x200000b8)

#define JumpHandle(TargetAddr)         (*((void(*)())(TargetAddr)))()	     //jump desPosition Address running
#define JumpHandle1(TargetAddr,a)      (*((void(*)())(TargetAddr)))(a)	   //jump desPosition Address running
#define JumpHandle2(TargetAddr,a,b)    (*((void(*)())(TargetAddr)))(a,b)	 //jump desPosition Address running
#define JumpHandle3(TargetAddr,a,b,c)  (*((void(*)())(TargetAddr)))(a,b,c) //jump desPosition Address running
#define JumpHandle4(TargetAddr,a,b,c,d)(*((void(*)())(TargetAddr)))(a,b,c,d) //jump desPosition Address running

// note: UDKv1迁移至UDKv2 请使用添加SAPI前缀
#define PREPDATA_HANDLE()        		  JumpHandle(0x00003564 + 1)	     // PrepData_Handle();
#define BBE_PREPINIT(a)                JumpHandle1(0x00000AC4+1,a) 	   // BBE_PrepInit(PARAM_DATAPREP *sCfg);
#define RF_VENUS_INIT()            	  JumpHandle(0x0000438C + 1)	     // RF_Venus_Init();
#define ANACFG_SET(a)                  JumpHandle1(0x00004F7C+1,a)      // anaCfg_Set(ANACFG *sCfg)
#define P2_FFT_HANDLE(a)               JumpHandle1(0x00003350+1,a)      // P2_FFT_Handle(P2_FFT_CONFIG *sCfg)
#define P2_FFT_STEPCFG8_HANDLE(a,b)    JumpHandle2(0x00003430+1,a,b)    // P2_FFT_StepCfg8_Handle(P2_FFT_CONFIG *sCfg,uint32_t Step)
#define RF_VENUS_DEINIT()        		  JumpHandle(0x00004378 + 1)	     // RF_Venus_DeInit();
#define BBE_WAITISR(a)                 JumpHandle1(0x00000B20+1,a) 	   // BBE_waitISR(uint64_t val);
#define CFAR_HANDLE(a)                 ((uint32_t (*)(CFAR_CONFIG *))(0x00000B48+1))(a)      // uint32_t CFAR_Handle(CFAR_CONFIG *sCfg);
#define ANGLE_SEQ_PRE(a)               JumpHandle1(0x00004F9C+1,a)      // void angleSeqPre(PARAM_DATAPREP *sCfg);
#define FFT3D_PRE_HANDLE(a,b)          JumpHandle2(0x00000D68+1,a,b)    // void FFT3D_Pre_Handle(FFT3D_PRE *sCfg,STRUCT_POINTRST *sRst);
#define COPYWIN_HANDLE(a,b)            JumpHandle2(0x00000C53+1,a,b)    // CopyWin_Handler((uint16_t *)&winRange[0],&paramDataPrep->winRange);
#define SLOW_CLK_DELAY2MS()            JumpHandle(0x00005D69 + 1)       // void slow_clk_delay2ms(void)
#define PROTOCOL_SENDPACK(a,b)         JumpHandle2(0x0000381c+1,a,b)    // uint32_t ProtocolSendPack(STRUCT_POINTRST *sRst,uint8_t *sBuff)
#define WDT_RSTNOW()                   JumpHandle(0x00004e20 + 1)       // void WDT_RstNow(void);

#define CMPHIT_CFAR_TARGET(a,b,c,d,e,f) ((void (*)(uint16_t aLen,BBE_CFARRST_T *aArray,uint16_t bLen,BBE_CFARRST_T *bArray,_Bool *hitAFlag,_Bool *hitBFlag))(0x0000508C+1))(a,b,c,d,e,f)
//#define EXFLASH_ENABLE_QUAD_MODE()     JumpHandle(0x000050f8 + 1)	      // exflash_enable_quad_mode();
//#define READ_EXT_FLASH_QUAD(a,b,c)     JumpHandle3(0x00005A84+1,a,b,c)   // read_ext_flash_Quad(uint32_t r_addr, uint8_t *r_buf, uint16_t read_len)
//#define EXTFLASH_READ_DATA(a,b,c,d)    JumpHandle4(0x00004e60+1,a,b,c,d) // exflash_read_data(uint32_t addr, uint8_t *data_buf, uint32_t length, enum exflash_read_t mode);																										  

//#define RTC0_START(a)    						  JumpHandle1(0x00004630+1,a)       // RTC0_Start(uint32_t sMsec)
//#define RTC1_START(a)    						  JumpHandle1(0x000046E8+1,a)       // RTC1_Start(uint32_t sMsec)
//																												  
//#define GPIO_DEFAULT_STATUS(a) 		    JumpHandle(0x00002744+1)          // GPIO_Default_Status()


#elif (APPLICATION_MODE == APPLICATION_MODE_XIP_START)

#define UART_RECV_STRUCT_BASE (0x20000000)

#define PREPDATA_HANDLE         SAPI_PREPDATA_HANDLE
//#define ANACFG_SET              SAPI_ANACFG_SET
//#define BBE_PREPINIT            SAPI_BBE_PREPINIT
//#define RF_VENUS_INIT           SAPI_RF_VENUS_INIT
//#define BBE_WAITISR             SAPI_BBE_WAITISR
//#define RF_VENUS_DEINIT         SAPI_RF_VENUS_DEINIT
//#define P2_FFT_STEPCFG8_HANDLE  SAPI_P2_FFT_STEPCFG8_HANDLE
//#define P2_FFT_HANDLE           SAPI_P2_FFT_HANDLE
#define ANGLE_SEQ_PRE           SAPI_ANGLE_SEQ_PRE
#define FFT3D_PRE_HANDLE        SAPI_FFT3D_PRE_HANDLE
//#define WDT_RSTNOW              SAPI_WDT_RSTNOW
#define CFAR_HANDLE             SAPI_CFAR_HANDLE
#define CMPHIT_CFAR_TARGET      SAPI_CMPHIT_CFAR_TARGET

//#define PREPDATA_HANDLE           udsf_prepdata_handle
#define ANACFG_SET                udsf_anacfg_set
#define BBE_PREPINIT              udsf_bbe_prepinit
#define RF_VENUS_INIT             udsf_rf_venus_init
#define BBE_WAITISR               udsf_bbe_waitisr
#define RF_VENUS_DEINIT           udsf_rf_venus_deinit
#define P2_FFT_STEPCFG8_HANDLE    udsf_p2_fft_stepcfg8_handle
#define P2_FFT_HANDLE             udsf_p2_fft_handle
//#define ANGLE_SEQ_PRE             udsf_angle_seq_pre
//#define FFT3D_PRE_HANDLE          udsf_fft3d_pre_handle
#define WDT_RSTNOW                udsf_wdt_rstnow
//#define CFAR_HANDLE               udsf_cfar_handle
//#define CMPHIT_CFAR_TARGET        udsf_cmphit_cfar_target
// 为确保应用兼容，XIP内需要具备ROM模式内所列SAPI
#include "sys_api.h"

#else
#error UNKNOWN_APPLICATION_MODE
#endif

#endif
